﻿using System.Collections.Generic;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SSG.Model;
using SSG.Tools;

namespace SSG.UnitTests
{
    /// <summary>
    /// Serialization tests
    /// </summary>
    [TestClass]
    public class Serialization
    {
        /// <summary>
        /// Serialize Settings
        /// </summary>
        [TestMethod]
        public void SerializeSetting()
        {
            List<FieldInfo> badFields;
            Setting s = Setting.OrderByRunway;
            bool serializeTest = s.CheckFieldSerialization(out badFields);
            Assert.IsTrue(serializeTest, "Critical fields for " + s.GetClassname());
            string msg;
            string xml = s.ObjectToXml(out msg);
            Assert.IsFalse(string.IsNullOrEmpty(xml), "No XML settings data");
            Assert.IsTrue(string.IsNullOrEmpty(msg), "XML serialization message: " + msg);
        }

        /// <summary>
        /// Serialize Settings
        /// </summary>
        [TestMethod]
        public void SerializeGeneratorSettings()
        {
            List<FieldInfo> badFields;
            GeneratorSettings gs = new GeneratorSettings();
            bool serializeTest = gs.CheckFieldSerialization(out badFields);
            Assert.IsTrue(serializeTest, "Critical fields for " + gs.GetClassname());
            string msg;
            string xml = gs.ObjectToXml(out msg);
            Assert.IsFalse(string.IsNullOrEmpty(xml), "No XML data for " + gs.GetClassname());
            Assert.IsTrue(string.IsNullOrEmpty(msg), "XML serialization message: " + msg);
        }
    }
}